<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="订单编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderCode">
              <a-input v-model="model.orderCode" placeholder="请输入订单编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountId">
              <a-input v-model="model.accountId" placeholder="请输入用户"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">
            <a-form-model-item label="车辆类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carTypeId">
              <a-input-number v-model="model.carTypeId" placeholder="请输入车辆类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>-->

          <a-col :span="24" >
            <a-form-model-item  label="车辆类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carTypeId">
              <EBikeTypeDialog v-model="model.carTypeName" :id.sync="model.carTypeId"></EBikeTypeDialog>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车辆id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carId">
              <a-input-number v-model="model.carId" placeholder="请输入车辆id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="套餐id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packageConfId">
              <a-input-number v-model="model.packageConfId" placeholder="请输入套餐id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户套餐id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountPackageId">
              <a-input-number v-model="model.accountPackageId" placeholder="请输入用户套餐id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderType">
<!--              <a-input-number v-model="model.orderType" placeholder="请输入订单类型 1-租赁支付 2-续租支付 3-超时支付" style="width: 100%" />-->
              <a-select v-model="model.orderType" placeholder="请选择订单类型">
                <a-select-option v-for="item in orderTypeDict" :key="item.value" :value="item.value">
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>


          <a-col :span="24">
            <a-form-model-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderStatus">
              <a-select v-model="model.orderStatus" placeholder="请选择订单状态">
                <a-select-option v-for="item in orderStatusDict" :key="item.value" :value="item.value">
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderAmount">
              <a-input-number v-model="model.orderAmount" placeholder="请输入订单金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="优惠金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discountAmount">
              <a-input-number v-model="model.discountAmount" placeholder="请输入优惠金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实付金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payAmount">
              <a-input-number v-model="model.payAmount" placeholder="请输入实付金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payTime">
              <j-date placeholder="请选择支付时间" v-model="model.payTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="购买计数（多少小时/天/月）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="count">
              <a-input-number v-model="model.count" placeholder="请输入购买计数（多少小时/天/月）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import EBikeTypeDialog from '@/components/rental/dialog/EBikeTypeDialog.vue'
  export default {
    name: 'RentalOrderForm',
    components: {
      EBikeTypeDialog
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        typelistdata:[],
        confirmLoading: false,
        validatorRules: {
        },
        orderTypeDict:[
          {
          label: "租赁支付",
          value: 1
          },
          {
          label: "续租支付",
          value: 2
          },
          {
          label: "超时支付",
          value: 3
          },
        ], orderStatusDict:[
          {
          label: "未支付",
          value: 1
          },
          {
          label: "已支付",
          value: 2
          },
          {
          label: "已取消",
          value: 3
          },
        ],
        url: {
          add: "/rental/order/add",
          edit: "/rental/order/edit",
          queryById: "/rental/order/queryById",
          typelist:"/rental/ebike-type/list",
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.gettypelist();
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      gettypelist(){
        let that=this;
        let data={pageSize:100,pageNo:1}
        getAction(this.url.typelist,data).then((res)=>{
          let datass=[]
          res.result.records.forEach(itme=>{
            datass.push({name:itme.carTypeName,id:itme.id})
          })
          this.typelistdata=datass;
          console.log(datass,"gettypelist")
        }).finally(() => {

        })
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>